/**
 * 推荐列表
 */
class RecommendUI extends BaseComp{
    private list_group:eui.Group;
    private Timer:egret.Timer;
    private curLastItemIndex:number;
    constructor()
    {
        super('RecommendView')
    }

    public init()
    {
        let list = RoleCache.instance().curMiniList;
        for(let v of list)
        {
            let index = list.indexOf(v);
            let item:BoxRenderUI = new BoxRenderUI(v);
            item.name = 'item_'+index;
            this.list_group.addChild(item);
            item.y = this.list_group.height - item.height >> 1;
            item.x = (14 + item.width) * index;
            this.curLastItemIndex = index;
        }
        this.Timer = new egret.Timer(100/3);
        egret.setTimeout(()=>{
            this.Timer.start();
        },this,1000)
        
        // if(!this._listDataArr)
        // {
        //     this._listDataArr = new eui.ArrayCollection(list);
        // }
        // this.recommend_list.dataProvider = this._listDataArr;
        // this.recommend_list.itemRenderer = BoxRenderUI;
    }

    public addEvent()
    {
        this.Timer.addEventListener(egret.TimerEvent.TIMER, this.timeHandle, this);
    }

    public timeHandle()
    {
        let len = this.list_group.numChildren;
        for(let i=0;i<len;i++)
        {
            let item = this.list_group.getChildByName('item_'+i);
            item.x -= 3;
            if(item.x <= -item.width)
            {
                let lastItem = this.list_group.getChildByName('item_'+this.curLastItemIndex);
                item.x = lastItem.x + (item.width + 14);
                this.curLastItemIndex = i;
            }
        }
    }

    public removeEvent()
    {
        this.Timer.removeEventListener(egret.TimerEvent.TIMER, this.timeHandle, this);
    }

    public clear()
    {
        super.clear();
        this.Timer.stop();
        this.Timer = null;
    }
}

window['RecommendUI'] = RecommendUI;